

export function errMsg(ec: number) {
    switch (ec) {
        case 0: return '正常';
        case 0x01: return 'FLASH ERR';
        case 0x02: return 'STORE_SUM_FAIL';
        case 0x03: return '解析参数错误';
        case 0x04: return '参数无效';
        case 0x05: return 'OTA ID INVALID';
        case 0x06: return 'OTA_MD5_INVALID';
        case 0x07: return 'OTA_PKG_INVALID';
        case 0x08: return '门打开失败';
        case 0x09: return '喷嘴堵转';
        case 0x0A: return '喷嘴超时';
        case 0x0B: return '扫码超时';
        case 0x0C: return '扫码非法的返回';
        default: return `未知错误:${ec}`;
    }
}

export class ExecErr {

    msg: string;

    constructor(ec: number) {
        this.msg = errMsg(ec);
    }
};

export class TimeoutErr {
    msg: string;

    constructor(msg: string) {
        this.msg = msg;
    }
}

export function errorMessage(e: any) {
    if (e instanceof ExecErr) {
        return e.msg;
    } else if (e instanceof TimeoutErr) {
        return e.msg;
    } else {
        return e as string;
    }
}

